import Vue from 'vue'
import Vuex from 'vuex'
import prop from '../../properties.js'

Vue.use(Vuex)
const ajax = {
	serveGet(properties) {
		properties.url = prop.server + prop.rootPath + properties.url;
		this.get(properties);
	},
	servePost(properties) {
		properties.url = prop.server + prop.rootPath + properties.url;
		this.post(properties);
	},
	get(properties) {
		properties.method = "GET"
		this.doRequest(properties)
	},
	post(properties) {
		properties.method = "POST"
		this.doRequest(properties)
	},
	doRequest(properties) {
		uni.request({
			url: properties.url,
			method: properties.method,
			data: properties.data,
			header: properties.header ? properties.header : '',
			success(res) {
				properties.success(res)
			}
		})
	}
}
export default ajax
